package com.jy.servlet;

import com.alibaba.fastjson.JSON;
import com.jy.bean.Consignee;
import com.jy.service.ConsigneeService;
import com.jy.service.impl.ConsigneeSericelmpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class merchant_Modify_goods extends HttpServlet {
    private static final Logger log = LoggerFactory.getLogger(merchant_inquire_consigneeServlet.class);
    private ConsigneeService consigneeService;
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String consignee_name = request.getParameter("consignee_name");
        String type = request.getParameter("consignee_type");
        String price = request.getParameter("consignee_price");

        Integer consignee_price = 0;
        //如果添加商品的单价不为空就转为Integer类型
        if (price.trim().length() != 0){
            consignee_price = Integer.parseInt(price);
        }

        consigneeService = new ConsigneeSericelmpl();

        boolean favg = consigneeService.updateMerchandise(new Consignee(null,consignee_name,type,consignee_price,null,null));
        merchant_Add_MerchandiseServlet.merchant_consignee_name=consignee_name;
        log.debug(merchant_Add_MerchandiseServlet.merchant_consignee_name);
        String data = JSON.toJSONString(favg);

        response.setContentType("application/json");
        response.setCharacterEncoding("utf-8");
        PrintWriter out = response.getWriter();
        out.println(data);
        log.debug("data:" +data);
    }
}
